import axios from '@/utils/requset'
import {getToken} from '@/utils/token'
export const getAllchannesAPI =()=>{
    return axios({
        url:'/v1_0/channels',
        method:'GET'
       
    })
}
export const loginAPI = ({mobile,code})=>{
    return axios ({
        url:'/v1_0/authorizations',
        method:'POST',
        data:{
            mobile,
            code
        }
        
    })
}
export const getUserChannesAPI = () =>{
    return axios ({
        url:'/v1_0/user/channels',
        method:'GET',
        headers:{
            Authorization:`Bearer ${getToken()}`
        }
        
    })
}
//用户关注
export const userFollowedAPI = ({userId}) =>{
    return axios ({
        url:'/v1_0/user/followings',
        method:'POST',
       data:{
        target:userId
       }
        
    })
}
//取消关注
export const userUnFollowedAPI = ({userId}) =>{
    return axios ({
        url:`/v1_0/user/followings/${userId}`,
        method:'DELETE',
      
        
    })
}
// 文章 - 点赞
export const articleLikeAPI = ({ target }) => {
    return axios({
      url: '/v1_0/article/likings',
      method: 'POST',
      data: {
        target: target
      }
    })
  }
  
  // 文章 - 取消点赞
  export const articleDisLikeAPI = ({ artId }) => {
    return axios({
      url: `/v1_0/article/likings/${artId}`,
      method: 'DELETE'
    })
  }

export const getAllArticleListAPI = ({channel_id,timestamp})=>{
    return axios ({
        url:'/v1_0/articles',
        method:'GET',
        headers:{
            Authorization:`Bearer ${getToken()}`
        },
        params:{
            channel_id,
            timestamp
        }
    })
}
//文章详情
export const detailAPI = ({artId})=>{
    return axios ({
        url:`/v1_0/articles/${artId}`,
        method:'GET',
        
    })
}
export const articleDislikeAPI = ({target}) =>{
    return axios({
        url: '/v1_0/article/dislikes',
        method: 'POST',
        data: {
          target: target
        },
        headers: {
            Authorization:`Bearer ${getToken()}`
        }
    })
}

export const reportArticleAPI = ({target,type}) =>{
    return axios({
        url: '/v1_0/article/reports',
        method: 'POST',
        data: {
          target: target,
          type:type,
        }
    })
}
//更新覆盖频道
export const updateChannelAPI = ({channels}) =>{
    return axios({
        url: '/v1_0/user/channels',
        method: 'PUT',
        data: {
          channels:channels//用户选择的整个数组
        }
    })
}
//删除
export const removeChannelAPI = ({channelID}) =>{
    return axios({
        url: `/v1_0/user/channels/${channelID}`,
        method: 'DELETE',
       
    })
}
//搜索建议
export const suggestListAPI = ({ q }) => {
    return axios({
      url: '/v1_0/suggestion',
      params: {
        q: q
      }
    })
  }
  //搜索结果
  export const suggestResultAPI = ({page = 1,per_page=10, q }) => {
    return axios({
      url: '/v1_0/search',
      method:'GET',
      params: {
        page,
        per_page,
        q
      }
    })
  }
  //获取评论列表
  export const commentsListAPI = ({id,offset=null,limit=10 }) => {
    return axios({
      url: '/v1_0/comments',
      method:'GET',
      params: {
        type:'a',
        source:id,
        offset,
        limit
      }
    })
  }
//   评论--点赞取消
export const commentLiKingAPI = ({id}) => {
    return axios({
      url: '/v1_0/comment/likings',
      method:'POST',
      data: {
        target:id
      } 
    })
  }
  export const commentDisLiKingAPI = ({target}) => {
    return axios({
      url: `/v1_0/comment/likings/${target}`,
      method:'DELETE',
  
    })
  }
  //发布评论
  export const sendCommentAPI = ({ artId, content }) => {
    return axios({
      url: '/v1_0/comments',
      method: 'POST',
      data: {
        target: artId,
        content: content
      }
    })
  }
// 获取用户信息
export const userInfoAPI = () => {
    return axios({
      url: '/v1_0/user'
    })
  }
  //获取用户资料
export const userProfileAPI = () =>{
  return axios({
    url:'/v1_0/user/profile'
  })
}
// 用户- 更新头像
// 注意: formObj的值必须是一个表单对象
// '{"a": 10, "b": 20}' // 对象格式的JSON字符串
// new FormData() // 表单对象
export const updatePhotoAPI = (formObj) => {
  return axios({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: formObj
    // 如果你的请求体内容是表单对象, 浏览器会自动携带请求头Content-Type为multipart/form-data
  })
}
//更新用户名称
export const updateProfileAPI = ({ birthday, userName }) =>{
  return axios ({
    url:'/v1_0/user/profile',
    method: 'PATCH',
    data: {
      birthday: birthday,
      name: userName
    }
  })
}


// 刷新token


export const refreshTokenAPI = () =>{
  return axios ({
    url: '/v1_0/authorizations',
    method: 'PUT',
    // 请求拦截器里面带的是token.而现在带的是refresh_token所以要axios哪里判断一下
    headers: {
      Authorization: 'Bearer '+localStorage.getItem('refresh_token')
    }
  })
}






 